package org.infosys.org.service.impl;

import org.infosys.basic.utils.PageList;
import org.infosys.org.domain.Department;
import org.infosys.org.mapper.DepartmentMapper;
import org.infosys.org.query.DepartmentQuery;
import org.infosys.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    /**
    * @Title: loadAll
    * @Description: 查询所有部门
    * @Author: hank
    * @Version: 1.0
    * @Date:  2022/6/21 17:43
    * @Parameters: []
    * @Return java.util.List<org.infosys.org.domain.Department>
    */
    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    @Override
    /** 
    * @Title: loadById
    * @Description: 根据id查询部门
    * @Author: hank
    * @Version: 1.0
    * @Date:  2022/6/21 17:33  
    * @Parameters: []
    * @Return org.infosys.org.domain.Department
    */
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }

    /**
    * @Title: save
    * @Description: 新增一个部门
    * @Author: hank
    * @Version: 1.0
    * @Date:  2022/6/21 17:43
    * @Parameters: [department]
    * @Return void
    */
    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.save(department);
    }

    /**
    * @Title: update
    * @Description: 修改部门信息
    * @Author: hank
    * @Version: 1.0
    * @Date:  2022/6/21 17:43
    * @Parameters: [department]
    * @Return void
    */
    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    /**
    * @Title: remove
    * @Description: 根据id删除一个部门
    * @Author: hank
    * @Version: 1.0
    * @Date:  2022/6/21 17:43
    * @Parameters: [id]
    * @Return void
    */
    @Override
    @Transactional
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

   /**
   * @Title: loadQuery
   * @Description: 分页高级查询部门信息
   * @Author: hank
   * @Version: 1.0
   * @Date:  2022/6/25 0:01
   * @Parameters: [departmentQuery]
   * @Return org.infosys.basic.utils.PageList<org.infosys.org.domain.Department>
   */
    @Override
    public PageList<Department> loadQuery(DepartmentQuery departmentQuery) {
        Integer count = departmentMapper.loadQueryCount(departmentQuery);
        List<Department> rows = departmentMapper.loadQuery(departmentQuery);
        return new PageList<Department>(count, rows);
    }
}
